﻿namespace Huayou.Common
{
    using Huayou.Utils;
    using System;
    using System.Data;
    using System.Web.UI.WebControls;

    public class CommonBaseLib
    {
        private int m_code = 0;
        private string m_dbFieldList = null;
        private string m_dbTable = null;
        private string m_filter = null;
        private string m_group = null;
        private string m_msg = null;
        private string m_order = null;

        protected DataTable CommonGetList()
        {
            string sqlString = "select " + this.DBFieldList + " from " + this.DBTable;
            if (this.Filter != null)
            {
                sqlString = sqlString + " where " + this.Filter;
            }
            if (this.Group != null)
            {
                sqlString = sqlString + " group by " + this.Group;
            }
            if (this.Order != null)
            {
                sqlString = sqlString + " order by " + this.Order;
            }
            DBAccess access = new DBAccess();
            DataTable table = access.RunProcedure(sqlString, this.DBTable);
            access.Close();
            return table;
        }

        public static void SetPage(DataGrid dg, DataTable dt)
        {
            DataGridUtils.SetPage(dg, dt);
        }

        public int Code
        {
            get
            {
                return this.m_code;
            }
            set
            {
                this.m_code = value;
            }
        }

        public string DBFieldList
        {
            get
            {
                return this.m_dbFieldList;
            }
            set
            {
                this.m_dbFieldList = value;
            }
        }

        public string DBTable
        {
            get
            {
                return this.m_dbTable;
            }
            set
            {
                this.m_dbTable = value;
            }
        }

        public string Filter
        {
            get
            {
                if ((this.m_filter == null) || this.m_filter.Equals(""))
                {
                    return null;
                }
                return this.m_filter;
            }
            set
            {
                if (value == null)
                {
                    this.m_filter = null;
                }
                else if (!value.Equals(""))
                {
                    if ((this.m_filter == null) || this.m_filter.Equals(""))
                    {
                        this.m_filter = value;
                    }
                    else
                    {
                        this.m_filter = this.m_filter + " and " + value;
                    }
                }
            }
        }

        public string Group
        {
            get
            {
                if ((this.m_group == null) || this.m_group.Equals(""))
                {
                    return null;
                }
                return this.m_group;
            }
            set
            {
                this.m_group = value;
            }
        }

        public string Msg
        {
            get
            {
                return this.m_msg;
            }
            set
            {
                this.m_msg = value;
            }
        }

        public string Order
        {
            get
            {
                if ((this.m_order == null) || this.m_order.Equals(""))
                {
                    return null;
                }
                return this.m_order;
            }
            set
            {
                this.m_order = value;
            }
        }

        public string OrFilter
        {
            set
            {
                if (value == null)
                {
                    this.m_filter = null;
                }
                else if (!value.Equals(""))
                {
                    if ((this.m_filter == null) || this.m_filter.Equals(""))
                    {
                        this.m_filter = value;
                    }
                    else
                    {
                        this.m_filter = this.m_filter + " or " + value;
                    }
                }
            }
        }

        public string RawFilter
        {
            set
            {
                if (value == null)
                {
                    this.m_filter = null;
                }
                else if (!value.Equals(""))
                {
                    if ((this.m_filter == null) || this.m_filter.Equals(""))
                    {
                        this.m_filter = value;
                    }
                    else
                    {
                        this.m_filter = this.m_filter + " " + value;
                    }
                }
            }
        }
    }
}

